package com.kaigejava.javanotebook.threaddemo.ruturndemo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author kaigejava
 * 使用线程池创建线程
 */
public class ThreadPoolReturnDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newSingleThreadExecutor();
        List<Future> resultList = new ArrayList<>();
        for(int i = 0;i<5;i++){
            ThreadPoolReturnDemoParam threadPoolReturnDemoParam =new ThreadPoolReturnDemoParam();
            Future future= pool.submit(threadPoolReturnDemoParam);
            resultList.add(future);
        }
        pool.shutdown();
        for(int i = 0;i<resultList.size();i++){
            Future future = resultList.get(i);
            System.out.println("第："+i+"个。返回结果是:"+future.get());
        }
    }




}
